package sensors;

import lejos.nxt.ColorSensor;
import lejos.nxt.LightSensor;
import lejos.nxt.SensorPort;
import lejos.robotics.Color;
import navigation.Navigation;
import protocol.Protocol.Field;

public class Grid {

	private LightSensor lightSens;
	private ColorSensor colorSens;
	private ColorSensor colorSens2;
	private LightSensor wallDetector;

	public static int red = Color.RED;
	public static int green = Color.GREEN;
	public static int free = Color.WHITE;
	public static int goal = Color.BLACK;

	public static int lightRed = 470;
	public static int lightGreen = 370;
	public static int lightFree = 540;
	public static int lightGoal = 290;

	public Grid() {
		wallDetector = new LightSensor(SensorPort.S2);
		lightSens = new LightSensor(SensorPort.S4);
		colorSens = new ColorSensor(SensorPort.S1);
		colorSens.setFloodlight(false);
		colorSens2 = new ColorSensor(SensorPort.S4);
		colorSens2.setFloodlight(false);
		lightSens.setFloodlight(true);
	}

	/**
	 * returns the brightness
	 * 
	 * @return brightness measured by the lightSensor
	 */
	public int getBrightness() {
		return lightSens.getNormalizedLightValue();
	}

	/**
	 * returns the color of the left ColorSensor
	 * 
	 * @return Color of the left ColorSensor
	 */
	public int getColor() {
		return colorSens.getColorID();
	}

	/**
	 * returns the color of the right ColorSensor
	 * 
	 * @return the Color of the right ColorSensor
	 */
	public int getColor2() {
		return colorSens2.getColorID();
	}

	/**
	 * detects either wall or box (now deprecated)
	 * 
	 * @return Type of the obstacle
	 */
	public Field wallDetected() {
		if (Navigation.touch.movingBox()) {

			// Due to the fact that no boxes exist
			//
			// if (wallDetector.getNormalizedLightValue() < 50) {
			// return Field.BLOCK;
			// } else {
			// return Field.WALL;
			// }
			return Field.WALL;
		}

		return Field.FREE;
	}

}
